/*
 *@Author: 张楚
 *@Date: 2021-08-16 17:19:15
 *@Description: 下拉菜单
*/

import 'package:flutter/material.dart';

class Dropdown extends StatefulWidget {
  Dropdown({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _DropdownState createState() => new _DropdownState();
}

class _DropdownState extends State<Dropdown> {
  var language = 'english';

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: new Text(widget.title), actions: <Widget>[
        PopupMenuButton(
          child: Row(
            children: [
              Text('$language | '),
              Icon(
                Icons.keyboard_arrow_down,
                color: Colors.white,
              )
            ],
          ),
          onSelected: (value) {
            setState(() {
              language = value;
            });

            print(value);
          },
          itemBuilder: (_) {
            return [
              PopupMenuItem(
                  value: '',
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            'change language',
                            style: TextStyle(
                              fontFamily: 'Roboto',
                              fontWeight: FontWeight.w500,
                              fontSize: 14,
                            ),
                          ),
                          Icon(
                            Icons.keyboard_arrow_up,
                            color: Colors.black,
                          )
                        ],
                      ),
                      Divider(
                        color: Colors.grey,
                        thickness: 2,
                      ),
                    ],
                  )),
              PopupMenuItem(
                value: 'english',
                child: Text(
                  'english',
                  style: TextStyle(
                      fontFamily: 'Roboto',
                      fontWeight: FontWeight.w500,
                      fontSize: 14,
                      color:
                          language == 'english' ? Colors.blue : Colors.black),
                ),
              ),
              PopupMenuItem(
                value: 'espanol',
                child: Text(
                  'espanol',
                  style: TextStyle(
                      fontFamily: 'Roboto',
                      fontWeight: FontWeight.w500,
                      fontSize: 14,
                      color:
                          language == 'espanol' ? Colors.blue : Colors.black),
                ),
              ),
              PopupMenuItem(
                value: 'nederlands',
                child: Text(
                  'nederlands',
                  style: TextStyle(
                      fontFamily: 'Roboto',
                      fontWeight: FontWeight.w500,
                      fontSize: 14,
                      color: language == 'nederlands'
                          ? Colors.blue
                          : Colors.black),
                ),
              ),
              PopupMenuItem(
                value: 'polski',
                child: Text(
                  'polski',
                  style: TextStyle(
                      fontFamily: 'Roboto',
                      fontWeight: FontWeight.w500,
                      fontSize: 14,
                      color: language == 'polski' ? Colors.blue : Colors.black),
                ),
              ),
            ];
          },
        ),
        const SizedBox(
          width: 12,
        )
      ]),
      body: new Center(
        child: Text('DEMO'),
      ),
    );
  }
}
